package com.xxx.hhh.demo.demo7;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
//        创建对象
        ServerSocket ss = new ServerSocket(10200);
        while (true) {
            Socket socket = ss.accept();
            BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\hhh" + Math.random() +".png"));
            int len;
            byte[] bytes = new byte[1024 * 8];
            while ((len = bis.read(bytes)) != -1){
                bos.write(bytes,0,len);
                bos.flush();
            }
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            bw.write("上传成功");

            bw.close();
            bos.close();
        }
//        ss.close();

    }
}